package com.quasar.hpatient.module.comm_compile;

import android.support.v4.view.ViewPager;
import android.widget.TextView;

import com.quasar.hpatient.R;
import com.quasar.hpatient.module.comm_login.LoginActivity;
import com.quasar.hpatient.module.comm_main.MainActivity;

import lib.quasar.base.frame.BaseActivity;
import lib.quasar.db.manager.DBManager;
import lib.quasar.widget.text.CircleTextView;

/**
 * description: 完善信息
 * created by kalu on 2018/4/9 11:10
 */
public class CompileActivity extends BaseActivity<CompilePresenter> implements CompileView {

    @Override
    public int initView() {
        return R.layout.activity_comm_compile;
    }

    @Override
    public void initDataLocal() {

        final ViewPager pager = findViewById(R.id.activity_comm_compile_pager);
        final TextView step2 = findViewById(R.id.doctor_compile_step2);

        findViewById(R.id.doctor_compile_step1).setOnClickListener(v -> {
            getPresenter().sorllPreview(this, pager, step2);
        });

        findViewById(R.id.doctor_compile_step2).setOnClickListener(v -> {
            getPresenter().sorllNext(this, pager, step2);
        });

        getPresenter().initAdapter(this, getSupportFragmentManager());
    }

    @Override
    public void initDataNet() {
    }

    @Override
    public void setTextColor(int id, int color) {
        TextView text = findViewById(id);
        if (null == text) return;
        text.setTextColor(getResources().getColor(color));
    }

    @Override
    public void setCirclrColor(int id, int color) {
        CircleTextView circle = findViewById(id);
        if (null == circle) return;
        circle.setCircleColor(getResources().getColor(color));
    }

    @Override
    public void setButton(int position) {
        boolean ok = (position == 0);
        setCirclrColor(R.id.activity_comm_compile_persion_num, ok ? R.color.color_bg_theme : R.color.color_font_gray40);
        setCirclrColor(R.id.activity_comm_compile_transplant_num, ok ? R.color.color_font_gray40 : R.color.color_bg_theme);
        setTextColor(R.id.activity_comm_compile_persion, ok ? R.color.color_bg_theme : R.color.color_font_gray40);
        setTextColor(R.id.activity_comm_compile_transplant, ok ? R.color.color_font_gray40 : R.color.color_bg_theme);
    }

    @Override
    public void setCompilePager(final CompileAdapter adapter) {
        ViewPager pager = findViewById(R.id.activity_comm_compile_pager);
        if (null == pager) return;
        pager.setOffscreenPageLimit(2);
        pager.setAdapter(adapter);
        pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }

            @Override
            public void onPageSelected(int position) {
                setButton(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });
    }

    @Override
    public void goMain() {
        goNext(MainActivity.class);
        onBackPressed();
    }

    @Override
    public void onBackPressed() {
        DBManager.getInstance().resetUserModel();
        goNext(LoginActivity.class);
        super.onBackPressed();
    }

    @Override
    public void updateMessage(int position, String str) {
        getPresenter().editModel(position, str);
    }
}